

package com.empresa.practicas;

import java.applet.Applet;
//import java.awt.Graphics;
import java.awt.*;

public class Hogueras extends Applet implements Runnable {

    int total = 20;
    int retardo = 150;
    int actual = 0;
    Image img[] = new Image[20];
    Thread hilo;

    @Override
    public void init() {
        for (int i = 0; i < total; i++) {
            img[i] = getImage(getDocumentBase(), "images/frame" + i + ".jpg");            
        }
    }

    @Override
    public void paint(Graphics g){
        g.drawImage(img[actual], 0, 0, this);
    }
    
    @Override
    public void start()
    {
        if(hilo==null)
        {
            hilo = new Thread(this);
            hilo.start();
        }
    }

    @Override
    public void run(){
      Thread esteHilo = Thread.currentThread();
        while (hilo == esteHilo){
          repaint();
          actual++;          
          if (actual > total){
            actual = 0;
          }
          try{
            //Thread.currentThread.sleep(retardo);
            esteHilo.sleep(retardo);
          }catch(InterruptedException ie){
          }
        } 
    }
    
    @Override
    public void stop(){
      hilo = null;
      }
    }
    


